package com.starsoft.quant.dao;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.starsoft.frame.core.orm.BaseDao;
import com.starsoft.quant.bean.QuantDetail;
import com.starsoft.quant.bean.QuantDetailId;

@Repository
public class QuantDetailDao extends BaseDao<QuantDetail, QuantDetailId> {

	public List<QuantDetail> getDetails(Integer acountId, Date date) {
		String hql = "from QuantDetail where id.acountId=?0 and id.date=?1";
		return this.find(hql, acountId, date);
	}
	
	public List<QuantDetail> getDetailsBetween(Integer acountId, Date begin, Date end) {
		String hql = "from QuantDetail where id.acountId=?0 and id.date>=?1 and id.date<=?2 order by id.date asc";
		return this.find(hql, acountId, begin, end);
	}

	public int deleteReportBetween(Integer acountId, Date beginDate, Date endDate) {
		int count;
		String hql = "delete from QuantDetail where  id.acountId = ?0";
		if (beginDate == null && endDate == null) {
			count = update(hql, acountId);
		} else if (beginDate != null && endDate != null) {
			hql += "  and id.date>=?1  and id.date<=?2";
			count = update(hql, acountId, beginDate, endDate);
		} else if (beginDate != null) {
			hql += "  and id.date>=?1";
			count = update(hql, acountId, beginDate);
		} else {
			hql += "  and id.date<=?1";
			count = update(hql, acountId, endDate);
		}
		return count;
	}
	
	public int delete(Integer acountId, Date date) {
		String hql = "delete from QuantDetail where  id.acountId = ?0 and id.date=?1";
		return update(hql, acountId, date);
	}
	
}
